package com.xumz.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xumz.dao.StudentDao;
import com.xumz.model.ClassName;
import com.xumz.model.Student;
import com.xumz.model.StudentManage;
import com.xumz.service.ClassService;
import com.xumz.service.StudentService;
@Service
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentDao cmDao;
	@Autowired
	ClassService classService;
	
	@Override
	public List<Student> selectStudent() {
		List<Student> list = cmDao.selectStudent();
		return list;
	}
	
	@Override
	public boolean stumembersadd(String stuname,String blogurl,String classoption) {
		return cmDao.stumembersadd(stuname,blogurl,classoption) > 0 ? true : false;
	}

	@Override
	public List<StudentManage> groupStudentBySerch(String teacherName,String classId,String studentName) {
		List<StudentManage> list =classService.selectAllStudentByTeacherName(teacherName);
		if (!classId.equals("所有班级")) {
			for (int i = 0; i < list.size(); i++) {
				if (!classId.equals(list.get(i).getClassId())) {
					list.remove(i);
					i--;
				}
			}
		}
		System.out.println(studentName);
		if (!studentName.equals("")) {
			for (int i = 0; i < list.size(); i++) {
				if (!list.get(i).getStuName().contains(studentName)) {
					list.remove(i);
					i--;
				}
			}
		}
		return list;
	}

	@Override
	public Student findStudentById(String id) {
		return cmDao.selectOne(id);
	}
	
	@Override
	public boolean stuinformationUpdate(Student student){
		return cmDao.stuinformationUpdate(student) > 0 ? true : false;
	}
	
	@Override
	public boolean bloginformationUpdate(Student student){
		return cmDao.bloginformationUpdate(student) > 0 ? true : false;
	}
	
	@Override
	public boolean classinformationUpdate(Student student){
		return cmDao.classinformationUpdate(student) > 0 ? true : false;
	}
	
	@Override
	public List<Student> selectStudentByClassId(String id){
		List<Student> list = cmDao.selectStudentByClassId(id);
		return list;
	}
	
	@Override
	public boolean stumemberDelete(String id){
		return cmDao.stumemberDelete(id) > 0 ? true : false;
	}
	
}
